<template>
  <div class="home">
    <!-- 头部开始 -->
    <div class="header">
      <div class="container w">
        <div class="container-logo">
          <a href="#" title="天奇图书" class="logo ir">
            <img src="../images/匠-书房.png" alt />
          </a>
        </div>
        <div class="container-title">
          <h2 class="title1">我的购物车</h2>
          <p class="title2">温馨提示：产品是否购买成功，以最终下单为准哦，请尽快结算</p>
        </div>
        <div class="container-info">
          <a href>登录</a>
          <span class="sep">|</span>
          <a href>我的订单</a>
        </div>
      </div>
    </div>

    <!-- 头部结束 -->
    <!-- 主页开始 -->
    <div class="shoping w">
      <!-- 主页上部分开始 -->
      <div class="shoping-head">
        <div class="col col-img">&nbsp;</div>
        <div class="col col-name">商品名称</div>
        <div class="col col-price">数量</div>
        <div class="col col-num">单价</div>
        <div class="col col-action">操作</div>
      </div>
      <div class="shoping-body" v-for="(item, index) in hearos3" :key="item.id">
        <a href>
          <img :src="item.images" alt />
        </a>
        <a href>
          <p class="title">{{ item.title}}</p>
        </a>
        <p></p>
        <button class="but1" @click="minus(index)">-</button>
        {{ item.num }}
        <!-- <input type="text" placeholder="1" /> -->
        <button class="but3" @click="add(index)">+</button>
        <p class="price">{{ item.price }}</p>
        <button class="but4" @click="drop(index)">
          <strong>删除该商品</strong>
        </button>
      </div>
      <!-- 主页上部分结束 -->
      <!-- 主页下部分开始 -->
      <div class="shoping-2"></div>
      <div class="shoping-footer">
        <a href class="but5">
          <router-link to="/sidebar_dlog">继续购物</router-link>
          <router-views></router-views>
        </a>
        <span class="but6">理性消费，祝亲购物愉快！</span>
        <span class="but7">
          合计:{{ totles }}元
          <router-link to="/order">
            <button class="but8" @click="shop">去结算</button>
          </router-link>
          <router-views></router-views>
        </span>
        <div class="footer1">
          <Fotter_dlog />
        </div>
      </div>
      <!-- 主页下部分结束 -->
      <!-- 主页结束 -->
    </div>
  </div>
</template>

<script>
import footer from "@/components/Fotter_dlog.vue";
import { mapState } from "vuex";
export default {
  name: "Cart",
  methods: {
    add(index) {
      this.$store.dispatch("addprices", index);
    },
    minus(index) {
      this.$store.dispatch("minusprices", index);
    },
    drop(index) {
      this.$store.commit("drop", index);
    },
    shop() {
      this.$store.dispatch("buys");
    },
  },
  data() {
    return {
      num: null,
    };
  },
  components: {
    footer,
  },
  computed: {
    totles() {
      // 总和初始化
      var totles = 0;
      // forEach循环
      this.hearos3.forEach((element) => {
        // 总价=价格*数量 的整合
        totles += element.price * element.num;
      });
      // 返回总价
      return parseInt(totles);
    },
    ...mapState(["hearos3"]),
  },
};
</script>

<style scoped>
body .el-table th.gutter {
  display: table-cell !important;
}
.w {
  width: 1200px;
  margin: 0 auto;
}
img {
  height: 48px;
  vertical-align: bottom;
}
.home {
  height: 100vh;
  /* display: block; */
  /* margin: left; */
  background-color: #f5f5f5;
}
.header {
  font-size: 12px;
  border-bottom: 2px solid #ff6700;
  background: #fff;
  color: #b0b0b0;
  position: relative;
  z-index: 20;
  height: 100px;
}
.container {
  width: 1200px;
  margin-right: auto;
  margin-left: auto;
  height: 100px;
  display: flex;
}
.container-logo {
  position: relative;
  display: block;
  width: 48px;
  height: 48px;
  margin-top: 20px;
  /* overflow: hidden; */
}
.container-title {
  width: 600px;
  height: 58px;
  margin-left: 55px;
  display: flex;
}
.title1 {
  margin-top: 30px;
}
.container-title h2 {
  color: #000;
  font-size: 20px;
}
.title2 {
  margin-left: auto;
  margin-top: 40px;
}
.container-info {
  width: 200px;
  height: 48px;
  margin-left: 470px;
  margin-top: 50px;
}
.shoping {
  width: 1200px;
  height: 300px;
  background-color: #fff;
  margin-top: 60px;
}
.shoping-head {
  height: 60px;
  /* display:block; */
  display: flex;
  padding-top: 10px;
  border-bottom: 1px solid #e0e0e0;
}
.shoping-body {
  height: 120px;
  margin-top: 3px;
  background-color: #ffffff;
  /* margin-left: 100px; */
}
.shoping-body img {
  margin-top: 30px;
  margin-left: 85px;
}
a .title,
.price {
  vertical-align: middle;
}
.shoping-body p {
  /* margin-top: 10px; */
  margin-left: 155px;
  width: 10%;
  overflow: hidden;
  display: block;
  white-space: nowrap;
  text-overflow: ellipsis;
  display: inline-block;
}
.shoping-body .price {
  margin-left: 134px;
}
.but1,
.but3 {
  border-radius: 50%;
}
.but1 {
  margin-left: -120px;
}
.but2 {
  width: 30px;
}
.but3 {
  margin-right: 60px;
}
.but4 {
  margin-left: 100px;
  color: red;
  cursor: pointer;
}
/* .shoping-body .yuan{
  display: inline-block;
  line-height: 120px;
  margin: 0;
} */
.shoping-2 {
  height: 20px;
  background-color: #f5f5f5;
}
.shoping-footer {
  /* padding-top: 10px; */
  height: 180px;
  line-height: 90px;
  background-color: #ffffff;
}
.col {
  margin-top: 20px;
  margin: auto;
  padding: 5px;
  /* border-bottom-style: solid; */
}
.but5 {
  margin-left: 32px;
}
a {
  text-decoration: none;
  color: #757575;
}
.but6 {
  margin-left: 26px;
  border-left: 1px solid #eee;
  padding-left: 16px;
}
.but7 {
  margin-left: 420px;
  color: #ff6700;
  font-size: 30px;
  font-style: normal;
}
.but8 {
  margin-top: 22px;
  margin-right: 70px;
  float: right;
  /* text-align: right; */
  color: #fff;
  background-color: #ff6700;
  width: 100px;
  height: 45px;
}
.footer1 {
}
imput {
  text-align: center;
}
</style>
